package com.java.controller;

import com.github.pagehelper.PageInfo;
import com.java.model.Help;
import com.java.model.Result;
import com.java.service.HelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/help")
public class HelpController {

    @Autowired
    private HelpService helpService;

    @GetMapping("list")
    public String toList(){
        return"/system/help/list";
    }

    @PostMapping("list")
    @ResponseBody
    public Result list(Help help){
        PageInfo<Help> pageInfo = helpService.list(help);
        return Result.success(pageInfo.getList(),pageInfo.getTotal());
    }


    @GetMapping("add")
    public String add(){
        return "/system/help/add";
    }


    @PostMapping("save")
    @ResponseBody
    public Result save(@RequestBody Help help){
        helpService.save(help);
        return Result.success();
    }
    @GetMapping("view")
    public String view(int id, Model model){
        Help help = helpService.get(id);
        model.addAttribute("helps",help);
        return "/system/help/view";
    }

    @GetMapping("edit")
    public String edit(int id, Model model){
        Help help = helpService.get(id);
        model.addAttribute("helps",help);
        return "/system/help/edit";
    }

    @PostMapping("modify")
    @ResponseBody
    public Result modify(@RequestBody Help help){
        helpService.modify(help);
        return Result.success();
    }

    @PostMapping("remove")
    @ResponseBody
    public Result remove(int[] ids){
        helpService.remove(ids);
        return Result.success();
    }
}
